package com.school.hjt.schoolclasscard.fragment

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.support.v7.widget.RecyclerView
import android.support.v7.widget.StaggeredGridLayoutManager
import android.view.View
import com.school.hjt.schoolclasscard.R
import com.school.hjt.schoolclasscard.adapter.RongYuAdapter
import com.school.hjt.schoolclasscard.db.ClassAlbum
import com.school.hjt.schoolclasscard.model.PhotoFModel
import com.school.hjt.schoolclasscard.utlis.Constant

/**
 * Created by Administrator on 2017/6/25.
 *
 */
class TabRongYuFragment : BaseFragment(){
    var recyclerView: RecyclerView?=null
    override fun initView(view: View?) {
        recyclerView = view!!.findViewById(R.id.recycler_view)
    }
    var adapter: RongYuAdapter?=null
    var model: PhotoFModel?=null
    val list=ArrayList<ClassAlbum>()
    var fRongReceiver:FRongYuReceiver?=null
    override fun loadData() {
        fRongReceiver= FRongYuReceiver()
        activity.registerReceiver(fRongReceiver,filter())
        val recyclerViewLayoutManager =
                StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
        model= PhotoFModel()
        recyclerView!!.layoutManager = recyclerViewLayoutManager
//        val list=ArrayList<String>()
//        list.add("http://smart.gcihjt.com/file/down/upload_photo_2017_12_20171227093238211.jpg")
//        list.add("http://smart.gcihjt.com/file/down/upload_photo_2017_12_20171227093238278.jpg")
//        list.add("http://smart.gcihjt.com/file/down/upload_photo_2017_12_20171227092207920.jpg")
//        list.add("http://smart.gcihjt.com/file/down/upload_photo_2017_12_20171227092207568.jpg")
//        list.add("http://smart.gcihjt.com/file/down/upload_photo_2017_12_20171227092207652.jpg")
//        list.add("http://smart.gcihjt.com/file/down/upload_photo_2017_12_20171227092207980.jpg")
//        list.add("http://smart.gcihjt.com/file/down/upload_photo_2017_12_20171227092208563.jpg")
//        list.add("http://smart.gcihjt.com/file/down/upload_photo_2017_12_20171227093238211.jpg")
//        list.add("http://smart.gcihjt.com/file/down/upload_photo_2017_12_20171227093238278.jpg")
//        list.add("http://smart.gcihjt.com/file/down/upload_photo_2017_12_20171227092207920.jpg")
//        list+= home!!.ClassBanner()
        list+=model!!.SchBanner("2")
        adapter = RongYuAdapter(activity,list)
        recyclerView!!.adapter=adapter
    }

    override fun getLayoutResource(): Int {
        return R.layout.fragment_rongyu
    }
    /**
     * 广播类
     */
    inner class FRongYuReceiver : BroadcastReceiver() {
        override fun onReceive(context: Context, intent: Intent) {
            val action = intent.action
            when(action){
                Constant.RONGYU->{
                    list.clear()
                    list+=model!!.SchBanner("2")
                    adapter!!.notifyDataSetChanged()
                }
            }

        }
    }
    /**
     * @return IntentFilter 广播
     */
    private fun filter(): IntentFilter {
        val filter = IntentFilter()
        filter.addAction(Constant.RONGYU)
        return filter
    }
}